import Vue from 'vue'
import App from './App.vue'
import router from './router/index'
import store from './store'
import './plugins/element.js'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/global.css'
//配置axios
//配置请求根路径
import axios from 'axios'
Vue.prototype.$http = axios.create({
  baseURL:'http://localhost:3000/api'
})

//通过axios拦截器添加token验证
//还未实现
// axios.interceptors.request.use((config)=>{
//   console.log(config);
//   config.headers.Authorization = window.sessionStorage.getItem('token')
//   return config
// })

//全局捕获错误
Vue.prototype.$http.interceptors.response.use(res =>{
  return res
},err=>{
  console.log(err.response);
  if(err.response.data.message){
      Vue.prototype.$message({
          type:'error',
          message:err.response.data.message
      })
  }
  return Promise.reject(err)
})


Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
